The present invention relates generally to the field of computing. more particularly, the invention relates to a system and method for dynamically controlling audio gain.
In audio applications, the gain applied to a signal from an audio input device (e.g. a microphone) must be adjusted to compensate for differences in the hardware devices used, the voice of the speaker, the distance between the speaker and the audio input device, and so on. If the gain is set too high the signal may be amplified beyond the range of a digital converter and result in a clipped signal. As a result, any audio output reproduced from the signal may be distorted and incomprehensible. On the other hand, if the gain is set too low, any audio output reproduced from the signal may be too low to be clearly heard or may be undetectable.
Commonly, when an audio input application is run for the first time, input gain is set to a maximum and the audio signal is sampled from the input device. The gain is then adjusted until no clipping is detected on the input device. The input gain is thus set once the first time the application is run and each time thereafter that the application is run, the input device gain is set to this level. If conditions change, the level set when the application was run for the first time may no longer be appropriate for the new conditions. Examples of conditions which may result in such an effect are as follows: a different speaker uses the audio input device, the speaker is not at the same distance from the audio input device, the speaker speaks louder or softer or in some other way changes his speaking style, or an audio device is changed or reconfigured.
In view of the foregoing, there is a need for a system that overcomes the drawbacks of the prior art. The present invention addresses these shortcomings by monitoring the audio data coming from the audio input device while it is in use and adjusting the gain (volume) dynamically to obtain a clear strong input signal.
According to an aspect of the invention, the frequency of clipping of the audio input signal is tracked at different gain levels and an input level approaching a target clipping rate is ascertained. The target clipping rate may Ad vary from application to application but in general a target clipping rate is very low but not zero. If it is found that there is too much clipping, gain may be lowered, preferably by a small increment. Preferably gain will be lowered if the tracking history indicates that the clipping rate at the lowered gain is closer to the target clipping rate than the clipping rate at the present (unlowered) rate.
If it is determined that clipping occurs too infrequently, the gain level is increased. Thereafter, if it is determined that the gain level has caused clipping that exceeds the target clipping frequency, the gain level will be lowered again.